package com.evil.kingdom.controller.alive;

import com.evil.kingdom.handler.SseHandler;
import com.evil.kingdom.pojo.dto.alive.SseEmitterUTF8;
import lombok.AllArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;

/**
 * @author liyang
 * @date 2024-06-01 23:25
 */
@Controller
@AllArgsConstructor
@RequestMapping("/sse")
public class SseController {

    private final SseHandler sseHandler;

    /**
     * 连接大世界
     *
     * @return SseEmitterUTF8
     */
    @GetMapping(path = "/world", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitterUTF8 world() throws IOException {
        return sseHandler.world();
    }

    /**
     * 连接战场
     *
     * @return SseEmitterUTF8
     */
    @GetMapping(path = "/battlefield", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitterUTF8 battlefield(String name) throws IOException {
        return sseHandler.battlefield(name);
    }
}
